package jay.home.bet.domain.logic;

import java.util.List;
import java.util.Map;

import jay.home.bet.dao.CounterDao;
import jay.home.bet.dao.OddsDao;
import jay.home.bet.domain.Event;
import jay.home.bet.misc.Util;

class OddsServiceImpl implements OddsService
{

	private OddsDao oddsDao;
	private CounterDao counterDao;
	
	public Event getEvent(String eventid)
	{
		return oddsDao.getEvent(eventid);
	}

	public List<Event> getEvents(int page, int range)
	{
		return (List<Event>)oddsDao.getEvents(page, range);
	}

	public List<Event> getEventsByType(String type, int page, int range)
	{
		return (List<Event>)oddsDao.getEventsByType(type, page, range);
	}
	
	public Event getEventByComp(String compid)
	{
		return oddsDao.getEventByComp(compid);
	}

	public List<Event> getEventsByComp(String compid, int page, int range)
	{
		return oddsDao.getEventsByComp(compid, page, range);
	}

	public void insertEvent(Event event)
	{
		oddsDao.insertEvent(event);
	}
	
	public Event insertEvent(Event event , String compId)
	{
		Event nextEvent = oddsDao.getEventByComp(compId);
		
		nextEvent.setId(Util.uuid());
		
		nextEvent.setDaxiao(event.getDaxiao());
		nextEvent.setRangqiu(event.getRangqiu());
		nextEvent.setType("单式");
		
		insertEvent(nextEvent);
		
		return nextEvent;
	}

	public void updateEvent(Event event)
	{
		oddsDao.updateEvent(event);
	}
	
	public void updateEventsByComp(Event event)
	{
		oddsDao.updateEventsByComp(event);
	}
	
	public int getByEvent(String compId)
	{
		return oddsDao.getByEvent(compId);
	}

	public OddsDao getOddsDao()
	{
		return oddsDao;
	}

	public void setOddsDao(OddsDao oddsDao)
	{
		this.oddsDao = oddsDao;
	}

	public List<Event> getAliveEvents(int page, int range)
	{
		return oddsDao.getAliveEvents(page, range);
	}

	public List<Event> getMorningEvents(int page, int range)
	{
		return oddsDao.getMorningEvents(page, range);
	}

	public List<Event> getRunningEvents(int page, int range)
	{
		return oddsDao.getRunningEvents(page, range);
	}

	public List<Event> getSleepingEvents(int page, int range)
	{
		return oddsDao.getSleepingEvents(page, range);
	}
	
	public List<Event> getNoRunningEvents(int page, int range)
	{
		return oddsDao.getNoRunningEvents(page, range);
	}

	public List<Event> getUnsettledEvents(int page, int range)
	{
		return oddsDao.getUnsettledEvents(page, range);
	}

	public CounterDao getCounterDao()
	{
		return counterDao;
	}

	public void setCounterDao(CounterDao counterDao)
	{
		this.counterDao = counterDao;
	}
	
	public Map getCounter(String eventid)
	{
		return counterDao.query(eventid);
	}

	/**
	 * 太讨厌了 ， 我靠， ibatis的delete会出问题导致MYSQL挂掉， 不得已选了jdbc来执行删除。估计是spring配置的问题。
	 */
	public void deleteEvent(String eventid)
	{
//		oddsDao.deleteEvent(eventid); fuck!!!
		counterDao.deleteEvent(eventid);
	}

	public void increaseCounter(String oddname, String eventid)
	{
		counterDao.update(oddname, eventid);
	}

	public List<Event> getGunQiuEvents(int page, int range)
	{
		return oddsDao.getGunQiuEvents(page, range);
	}

	public List<Event> getDanshiEvents(int page, int range)
	{
		return oddsDao.getDanshiEvents(page, range);
	}

	public List<Event> getUnpublisedEvents(int page, int range)
	{
		return oddsDao.getUnsettledEvents(page, range);
	}
	
	public List<Event> getEvents(Map map, int page, int range)
	{
		return oddsDao.getEvents(map, page, range);
	}

	public int countEvents(Map map)
	{
		return oddsDao.countEvents(map);
	}
}